package com.bonc.apicreator.dao;


import java.util.List;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.transaction.annotation.Transactional;

import com.bonc.apicreator.entity.Project;


/**
 * project的dao层接口
 *
 * @author gaopengyu
 * @version 2016年8月5日
 * @see ProjectDao
 * @since
 */
@Transactional
public interface ProjectDao extends JpaRepository<Project, Long> {
    /**
     * Description: 根据工程名查询实例，用于重名校验
     * 
     * @param proName
     * @return Project
     * @see
     */
    Project findByName(String proName);

    /**
     * Description: 根据工程名模糊查询，返回分页数据
     * 
     * @param condition
     * @param pageable
     * @return Page<Project>
     * @see
     */
    Page<Project> findByNameContaining(String condition, Pageable pageable);

    /**
     * Description: 查询当前用户下的工程 按创建时间倒序排列
     * 
     * @param userId
     * @param pageable
     * @return Page<Project>
     * @see
     */
    Page<Project> findByCreateByOrderByCreateDateDesc(Long userId, Pageable pageable);

    /**
     * Description: 根据当前用户和工程名查询 按创建时间倒序排列
     * 
     * @param userId
     * @param condition
     * @param pageable
     * @return Page<Project>
     * @see
     */
    Page<Project> findByCreateByAndNameContainingOrderByCreateDateDesc(Long userId,
                                                                       String condition,
                                                                       Pageable pageable);

    /**
     * Description: 在当前用户的工程中进行重名校验
     * 
     * @param name
     * @param userId
     * @return Project
     * @see
     */
    Project findByNameAndCreateBy(String name, Long userId);

    /**
     * Description: code重名校验
     * 
     * @param name
     * @param userId
     * @return Project
     * @see
     */
    Project findByCodeAndCreateBy(String name, Long userId);

    /**
     * Description: context重名校验
     * 
     * @param name
     * @param userId
     * @return Project
     * @see
     */
    Project findByContextAndCreateBy(String name, Long userId);

    /**
     * Description: 查询当前用户的所有project
     * 
     * @param userId
     * @param textOnly
     * @return List<Project>
     * @see
     */
    List<Project> findByCreateBy(long id);
}
